import 'package:flutter/material.dart';
import 'package:wakelock/wakelock.dart';
import 'package:zego_express_engine/zego_express_engine.dart';
import 'package:zego_faceunity_plugin/zego_faceunity_plugin.dart';

class ZegoBuilder extends StatefulWidget {
  final Widget child;
  ZegoBuilder({@required this.child, Key key}) : super(key: key);

  @override
  _ZegoBuilderState createState() => _ZegoBuilderState();
}

class _ZegoBuilderState extends State<ZegoBuilder> {
  final int appID = 1071641345;
  final String appSign = '7047c6719f16743b309e81ee9708e1a937deebb20d4619f4ff546fdf7c863f7b';

  @override
  void initState() {
    super.initState();
    // 屏幕常亮
    Wakelock.enable(); 
    // 初始化
    ZegoExpressEngine.createEngine(appID, appSign, true, ZegoScenario.Communication);
    // 开启调试模式
    ZegoExpressEngine.instance.setDebugVerbose(true, ZegoLanguage.Chinese);
    // 设置视频配置
    ZegoExpressEngine.instance.setVideoConfig(
      ZegoVideoConfig.preset(ZegoVideoConfigPreset.Preset1080P),
    );
    // 启用硬件编码器
    ZegoExpressEngine.instance.enableHardwareEncoder(true);
    // 启用硬件解码器
    ZegoExpressEngine.instance.enableHardwareDecoder(true);
    // 设置自定义视频源
    ZegoFaceunityPlugin.instance.setCustomVideoCaptureSource(ZegoCustomSourceType.Camera);
    // 启用自定义视频捕获
    ZegoExpressEngine.instance.enableCustomVideoCapture(true);
  }

  @override
  Widget build(BuildContext context) => widget.child;
}
